package na.learn.java.corepatterns.caching;

/**
 * This class is composed of foll: 1. Key object passed in (Key, Value) pair. 2.
 * Instance of CompositeTime, which comtains BirthTime and Time-to-live for this
 * (Key,Value) pair.
 * 
 * @author nagrawal2
 * 
 */
public class CompositeKey {
	private Object key;

	private long birthTime;

	private long endTime;

	public CompositeKey(Object key, long timeToLive) {
		this(key, System.currentTimeMillis(), timeToLive);

	}

	public CompositeKey(Object key, long birthTime, long timeToLive) {
		this.key = key;
		this.birthTime = birthTime;
		this.endTime = birthTime + timeToLive;
	}

	public Object getKey() {
		return key;
	}

	public long getBirthTime() {
		return birthTime;
	}

	public void setBirthTime(long birthTime) {
		this.endTime = birthTime + (this.endTime - this.birthTime);
		this.birthTime = birthTime;
	}

	public long getEndTime() {
		return endTime;
	}

	public void setEndTime(long endTime) {
		this.endTime = endTime;
	}

	public void setKey(Object key) {
		this.key = key;
	}

}